package com.hx.controller;


import cn.hutool.db.Session;
import com.hx.entity.User;
import com.hx.exception.WebException;
import com.hx.result.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  购物车控制器
 * </p>
 *
 * @author zhangyiming
 * @since 2022-03-02
 */
@Controller
@RequestMapping("/cart")
@Slf4j
public class CartController {

    @GetMapping("/add/{productId}/{price}/{quantity}")
    public ModelAndView add(
            @PathVariable("productId") Integer productId,
            @PathVariable("price") Integer price,
            @PathVariable("quantity") Integer quantity,
            HttpSession session
    ){
        if(productId == null || price == null || quantity == null){
            log.info("[添加购物车]参数为空");
            throw new WebException(ResponseEnum.PARAMETER_NULL);
        }
        //判断是否为登录用户
        User user = (User) session.getAttribute("user");
        if(user == null){
            log.info("[添加购物车]当前为未登录状态");
            throw new WebException(ResponseEnum.NOT_LOGIN);
        }

        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }
}